package org.magicbox.qjunTPO.controller;


import org.magicbox.qjunTPO.common.lang.Result;
import org.magicbox.qjunTPO.entity.Deskusertype;
import org.magicbox.qjunTPO.service.DeskusertypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLIntegrityConstraintViolationException;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 欢迎添加科技实践队粉丝群：690849711
 * @since 2021-12-21
 */
@RestController
@RequestMapping("/deskusertype")
public class DeskusertypeController {
    @Autowired
    DeskusertypeService deskusertypeService;

    @PreAuthorize("hasAnyAuthority('DeskPower')")
    @RequestMapping(value = "/addDesk",method = RequestMethod.POST)
    public Result addDesk(@Validated @RequestBody Deskusertype desk) {
        Integer deskId = desk.getDeskId();
        if (deskId == null) return Result.fail("请为新桌子写上桌号");
        try {
            deskusertypeService.save(desk);
            return Result.success("桌子添加成功!");
        }catch (Exception e){
            return Result.fail("桌号已经存在,请检查系统中的桌子!");
        }
    }
}
